package org.ejc.api.country;

import java.util.Collection;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.naming.NamingException;

import org.ejc.persist.model.CountryCode;
import org.ejc.util.EJCUtils;
import org.hibernate.Criteria;
import org.hibernate.Session;


/**
 * @author zac
 * 
 * @ejb.bean type="Stateless" name="CountryAPI"
 *           description="CountryAPI session bean"
 *           local-jndi-name="org.ejc/CountryAPILocalHome"
 *           jndi-name="org.ejc/CountryAPIHome" view-type="both"
 * 
 * @ejb.ejb-ref ejb-name="CountryAPI" ref-name="ejb/CountryAPI"
 *              view-type="both"
 * 
 * @ejb.transaction type="RequiresNew"
 * @ejb.util generate = "physical"
 */
public abstract class CountryAPIBean implements SessionBean{
	
	
	/**
	 * Get a Listing of Countries
	 * 
	 * @ejb.interface-method view-type="both"
	 * 
	 */
	public Collection getCountryListing() throws NamingException, EJBException {
	
		Session hsession = null;
		try {
			hsession = EJCUtils.getHibernateSession();
			Criteria crit=hsession.createCriteria(CountryCode.class);
			return crit.list();
		}catch(Exception e){
			
		}finally{
			if(hsession!=null){
				hsession.close();
			}
		}
		return null;
	}	
}
